<?php $this->load->view('common/default_header.php');?>

<div class="container">
	<div class="row">
		<?php $this->load->view('common/index_nav.php');?>
		<form method="post" accept-charset="utf-8" id="regForm">
		  <div class="form-group">
		    <label for="phone">手机号码：</label>
		    <input type="text" name="phone" class="form-control" id="phone" placeholder="手机号码">
		  </div>
		  <div class="form-group">
		   	<label>
		      <a href="javascript:getSMSCode()" id="getSMSBtn" class="btn btn-primary">获取验证码</a>
		    </label>
		  </div>
		  <div class="form-group">
		    <label for="vaildCode">短信验证码：</label>
		    <input type="text" name="vaildCode" class="form-control" id="vaildCode" placeholder="短信验证码">
		  </div>
		  <div class="form-group">
		    <label for="password">密码：</label>
		    <input type="password" name="password" class="form-control" id="password" placeholder="密码">
		  </div>
		  <div class="form-group">
		    <label for="password2">确认密码：</label>
		    <input type="password" name="password2" class="form-control" id="password2" placeholder="确认密码">
		  </div>
		  <div class="checkbox">
		    <label>
		      <input type="checkbox" name="term" checked> 同意《比特博士》条款
		    </label>
		  </div>
		  <a href="javascript:reg()" class="btn btn-primary">注册</a>
		</form>
	</div>
</div>
<?php $this->load->view('common/default_footer.php');?>

<script type="text/javascript">
//倒计时操作
function countDown($button, time) {
    if (time > 0) {
        $button.addClass('disabled');
        $button.text("重新发送("+time+")");
        setTimeout(function () {
            countDown($button, --time);
        }, 1000);
    } else {
        $button.removeClass('disabled');
        $button.text("获取验证码");
    }
}

function getSMSCode(){
	var phone = $.trim($('#phone').val());
	var phoneReg = /^0?1[3|4|5|8][0-9]\d{8}$/;
	if (!phoneReg.test(phone)) {
	    alert("手机号码输入有误！");
	    return;
	}
	var disabled = $("#getSMSBtn").hasClass('disabled');
	if(disabled==undefined||disabled==false){
		$.ajax({
		    type: 'POST',
		    url: "/ajax/getSMSCode",
		    dataType: 'json',
		    data: {'type':'reg','area':86,'phone':phone} ,
		    success: function(data){
		    	if(data.errno==0 || data.errno==1){
		    		alert(data.msg);
		    		countDown($('#getSMSBtn'),data.data.expire);
		    	}else{
		    		alert(data.msg);
		    	}
		    }
		});
	}else{
		return;
	}
}

function reg(){
	$.ajax({
	   type: "POST",
	   url: "/reg/handle",
	   dataType: 'json',
	   data: $("#regForm").serialize(),
	   success: function(data){
	     	if(data.errno==0 ){
	    		$.post("/login/rync", {platform:data.data.platform,cooper:data.data.cooper,otp:data.data.otp,signmsg:data.data.signmsg,redirect:data.data.redirect},function(data){
					if(data.errno==0){
						location.href=data.data.redirect;
					}else{
						alert("登陆失败！");
					}
				}, "json");
	    	}else{
	    		alert(data.msg);
	    	}
	   }
	});
}
</script>

</body>


</html>